package cn.tsinghua.david.gc.obj;

import java.util.ArrayList;

import cn.tsinghua.david.gc.GCConstant;
import cn.tsinghua.david.gc.ifc.IGCDeduce;
import cn.tsinghua.david.gc.tool.GCCommonDeducer;

public class GCState {
	private String strStateDesc = "";
//	private IGCDeduce deducer = new GCCommonDeducer();
	private ArrayList<GCASPair> children = new ArrayList<GCASPair>();

	public ArrayList<GCASPair> getChildren() {
		return children;
	}

	public void setChildren(ArrayList<GCASPair> children) {
		this.children = children;
	}

	public GCState(String desc){
		this.strStateDesc = desc;
	}

	public String getStrStateDesc() {
		return strStateDesc;
	}

	public void setStrStateDesc(String strStateDesc) {
		this.strStateDesc = strStateDesc;
	}
	
//	public void setDeducer(IGCDeduce deducer) {
//		this.deducer = deducer;
//	}
	
	public void addChild(GCASPair child){
		if (!children.contains(child))
			children.add(child);
	}
	
	public void addAllChildren(ArrayList<GCASPair> pairs){
		for (GCASPair child : pairs){
			addChild(child);
		}
	}
	
	public void clearChildren(){
		children.clear();
	}
	
	public void removeChildren(GCASPair child){
		children.remove(child);
	}
	
//	public ArrayList<GCASPair> nextState(){
//		if (this.deducer == null){
//			return null;
//		}
//		return deducer.nextState(this);
//	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((strStateDesc == null) ? 0 : strStateDesc.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		GCState other = (GCState) obj;
		if (strStateDesc == null) {
			if (other.strStateDesc != null)
				return false;
		} else if (!strStateDesc.equals(other.strStateDesc))
			return false;
		return true;
	}

	public boolean isFinalState(){
		return this.equals(GCConstant.FINALGCSTATE);
	}
	
	
}
